#include <iostream>
#include <cmath>
#include <allegro.h>

using namespace std;

int main()
{
    double t,y,grx,gry,r=1,f,n,v,a;
    cout<<"Enter the number of harmonics to mix\n";
    cin>>n;
    cout<<"Enter the amplitude (in mm)\n";
    cin>>a;
    cout<<"Enter the frequency\n";
    cin>>f;
    allegro_init();
    install_keyboard();
    set_gfx_mode(GFX_AUTODETECT_WINDOWED,600,600,0,0);
	clear_to_color(screen,makecol(255,255,255));
    textout_ex(screen,font,"Fourier Analysis",192,125,makecol(0,0,0),-1);
    line(screen,100,230,100,430,makecol(0,0,0));
    textout_ex(screen,font,"^Y",80,330,makecol(0,0,0),-1);
    line(screen,100,330,625,330,makecol(0,0,0));
    textout_ex(screen,font,"X>",500,350,makecol(0,0,0),-1);
    for(t=0;t<=1;t=t+0.0001)
    {
        y=a/2;
        grx=100+(325*t);
        for(r=1;r<=n;r=r+2)
        {
            v=sin(r*f*t*6.28);
            y=y+(2*a*v)/(r*3.4);
            gry=330-(y*10);
            putpixel(screen,grx,gry,makecol(0,0,0));
        }
    }
    readkey();
}
END_OF_MAIN()
